
import CryptoJS from "crypto-js"

const CRYPTOJSKEY = 'adasdaqweqwe'

export function encrypt(plaintText) {
  let options = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  };
  let key =CryptoJS.enc.Utf8.parse(CRYPTOJSKEY)
  let encryptedData = CryptoJS.AES.encrypt(plaintText, key, options);
  return encryptedData.ciphertext.toString()
}

//解密
export function decrypt(encryptedBase64Str) {
  let options = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  };
  let key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
  let decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, options);
  let decryptedStr = CryptoJS.enc.Utf8.stringify(decryptedData);
  return decryptedStr;
}



// appid
export const appId = `123`
// 密钥
export const secret = `123`
// 系统信息
const systemInfo = uni.getSystemInfoSync()
// sign 值
export const getSign = function() {
	// console.log('appWgtVersion', systemInfo.appWgtVersion)
	let signObj = {
		appId: appId,
		time: new Date().getTime(),
		version: systemInfo.appWgtVersion,
		osType: systemInfo.osName == 'android' ? 0 : 1
	}

	return JSON.stringify(signObj)
}






